package cn.sjxy.baseLib;

import lombok.Data;
import org.slf4j.Logger;

/* 定义异常处理辅助类 */
@Data
public class SjuException extends RuntimeException {

    //异常类型的枚举
    public enum ExType {
        appEx, loginEx,
    }

    //异常类型
    private ExType exType;

    public SjuException(String exMsg) {
        super(exMsg);
    }

    //抛出程序执行异常提示
    public static void appEx(String msg) throws SjuException {
        SjuException ex = new SjuException(msg);
        ex.setExType(ExType.appEx);
        throw ex;
    }

    //抛出登录异常提示
    public static void loginEx(String msg) throws SjuException {
        SjuException ex = new SjuException(msg);
        ex.setExType(ExType.loginEx);
        throw ex;
    }

    //异常日志输出
    public static void logException(Logger log, String msg, Exception ex) {
        log.error("\r\n==================================================start");
        log.error("\r\n" + msg, ex);
        log.error("\r\n==================================================end");
    }
}
